$(document).ready(function(){
	//封装
	function getDeskInfo(){
		$.ajax({
			url:'dt_getDataList.action',
			type:'POST',
			dataType: 'json',
			success: function(data){
				if (data.status == "200") {
					$('.chashier_desk .row').empty('');
					for (var i = 0; i <data.data.length; i++) {
						var value = data.data[i];
						if(value.enumCode=='0'){
							$('.chashier_desk .row').append("<div class='col-md-2 close-desk' data-id='"+value.id+"'>"+value.name+"</div>");
						}
						else{
							$('.chashier_desk .row').append("<div class='col-md-2 open-desk'>"+value.name+"<span class='glyphicon glyphicon-user'></span><span class='glyphicon glyphicon-user'></span><span class='glyphicon glyphicon-user'></span></div>");
						}
					}
			}
				else{
					window.location.href = "error.html";
				}
		},
		});
	}
//点击开台
		$('body').on('click','.chashier_desk .row div',function(){
			var class_state=$(this).attr('class');
			var desk_name=$(this).text();
			var desk_id=$(this).attr('data-id');
			if(class_state=='col-md-2 open-desk'){
				alert('很抱歉，这桌已经有人了！');
			}
			else{
				if(class_state=='col-md-2 close-desk'){
				if(confirm("确认开台？")){
					$.ajax({
						url:'dt_changeDataState.action',
						dataType:'json',
						type:'POST',
						data:{
							'id':desk_id,	
							'enumCode':1,
							'enumName':'已开台',
						},
						success:function(){
							 $.session.set('diningTableID',desk_id);
							 $.session.set('diningTableName', desk_name);
							 window.location.href = "chashier_order.html";
							getDeskInfo();
							
						}
					});
				}
			}
				else{

			}
			}

		});
//	};
//	获取餐桌信息
	$.ajax({
		url:'dt_getDataList.action',
		type:'POST',
		dataType: 'json',
		success: function(data){
			if (data.status == "200") {
				for (var i = 0; i <data.data.length; i++) {
					var value = data.data[i];
					if(value.enumCode=='0'){
						$('.chashier_desk .row').append("<div class='col-md-2 close-desk' data-id='"+value.id+"'>"+value.name+"</div>");
					}
					else{
						$('.chashier_desk .row').append("<div class='col-md-2 open-desk' >"+value.name+"<span class='glyphicon glyphicon-user'></span><span class='glyphicon glyphicon-user'></span><span class='glyphicon glyphicon-user'></span></div>");
					}
				}
		}
			else{
				window.location.href = "error.html";
			}
	},
	}).done(function(){
	});

	
	
	
});